package com.innovation.chengzhangriji.service;

import android.app.Service;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;

import com.google.gson.JsonElement;
import com.innovation.chengzhangriji.Config;
import com.innovation.chengzhangriji.http.Client;
import com.innovation.library.http.InnovationHttpResponseHandler;

public class CheckVersionService extends Service {

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        String packageName = getPackageName();
        final String version = Config.VERSION;
        String channel = Config.CHANNEL;
        Client.requestCheckVersion(this, packageName, version, channel, new InnovationHttpResponseHandler() {

            @Override
            public void onInnovationSuccess(JsonElement value) {
                Intent intent1 = new Intent("UpdateInfo");
                intent1.putExtra("update_info", value.toString());
                LocalBroadcastManager.getInstance(CheckVersionService.this).sendBroadcast(intent1);
            }
        }, null);
        return super.onStartCommand(intent, flags, startId);
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}
